package com.group4.datafactorybackend.controller;

import com.group4.datafactorybackend.common.R;
import com.group4.datafactorybackend.entity.DTO.*;
import com.group4.datafactorybackend.service.DataAssertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author aKUN
 * @date 2022/7/29
 * @description 数据资产控制器层
 */
@Api(tags = "数据资产管理")
@RestController
@RequestMapping("/dataAssert")
public class DataAssertController {

    private final DataAssertService dataAssertService;

    @Autowired
    public DataAssertController(DataAssertService dataAssertService){
        this.dataAssertService = dataAssertService;
    }

    /**
    * @author 邹代鑫
    * @param createOrUpdateDataAssertDTO 新增、修改数据资产表接收参数实体类
    * @return R
    * @description 新增数据资产
    **/
    @ApiOperation("新增数据资产")
    @PostMapping("/post/createOrUpdateDataAssert")
    public R<?> createOrUpdateDataAssert(@RequestBody @Validated CreateOrUpdateDataAssertDTO createOrUpdateDataAssertDTO){
        return this.dataAssertService.createOrUpdateDataAssert(createOrUpdateDataAssertDTO);
    }

    /**
     * @author 章珑赢
     * @param dataAssertParameterDTO 查询数据资产表条件实体类
     * @return R
     * @description 根据条件查询数据资产表
     **/
    @ApiOperation("根据条件查询数据资产表")
    @PostMapping("/post/selectDataAssertBy")
    public R<?> selectDataAssertBy(@RequestBody DataAssertParameterDTO dataAssertParameterDTO){
        return dataAssertService.selectDataAssertBy(dataAssertParameterDTO);
    }

    /**
     * @author 李泓静
     * @param daCode 数据资产编号
     * @return R
     * @description 根据编号查询数据资产表详情
     */
    @ApiOperation("查询数据资产详情")
    @GetMapping("/get/getDataAssertDetail/{daCode}")
    public R<?> getDataAssertDetail(@PathVariable String daCode){
        //查询数据资产字段信息
        return dataAssertService.getDataAssertField(daCode);

    }

    /**
     * @author 卑微小峰
     * @param daCode 数据资产编号
     * @return R
     * @description 删除数据资产表
     */
    @ApiOperation("删除数据资产表")
    @DeleteMapping("/delete/deleteDataAssert/{daCode}")
    public R<?> deleteDataAssert(@PathVariable("daCode") String daCode) {
        return dataAssertService.deleteDataAssert(daCode);
    }

    /**
     * @author 卑微小峰
     * @param batchReleaseOrOutageDTO （批量）发布/停用接收参数实体类
     * @return R
     * @description （批量）发布/停用数据资产表
     */
    @ApiOperation("（批量）发布/停用数据资产表")
    @PutMapping("/update/releaseOrOutage")
    public R<?> releaseOrOutage(@RequestBody BatchReleaseOrOutageDTO batchReleaseOrOutageDTO) {
        return dataAssertService.releaseOrOutage(batchReleaseOrOutageDTO);
    }

}
